****** Emerging Researchers NSF Project 
****** The Impact of Federal R&D Funding Across the Academy: An Analysis of Early-Career Research Productivity  
****** Data Code: Part 1 - Wide Form Descriptive Statistics
****** Built October 2018, Public Version Created June 2019 

********************************************************************************

*** Open Data File for Part 1 (P1)
** Set Directory Path 

********************************************************************************

*** Part 1: Descriptive Statistics

** Globals
global pubs everpub priorpubs total_article_cum5 avgnewpub total_article_cum16 avgauthpub averageauthors total_rpub_cum16 total_article_c5yr_cum16 avgauthcite avgcitesperpub field_avg_pubs field_avg_cpp
global pistats grfp_yr award female ADV1female gendermatch div_cd1 div_cd2 div_cd3 div_cd4
global placement phdcomplete degreetime_cd fp_research fp_postdoc fp_academic fp_tt 
global gradinst gradpublic flagship_dc_invariant gradlandgrant gradtype_cc2 gradtype_cc3 gradtype_cc7 gradregion1 gradregion2 gradregion3 gradregion4 gradregion5 gradregion6 gradregion7 gradregion8 gradregion9
global gradprog rank1 rank2 rank3 size1 size2 size3 size4 avg_pubs_per_fac_nrc_dept avg_citations_per_pub_nrc_dept female_fac_pct_nrc_dept avg_GRE_nrc_dept grfpTot_iped_dept_prior2yr 
global bacontrols bacpublic bac_cd1 bac_cd2 bac_cd5 bac_cd6

** Descriptive Statistics on CCA Sample for Coarsened & By Award Status
* For Coarsened CCA Sample
foreach sample in cca2cemsample {
eststo clear 
eststo: estpost sum $pubs $pistats $placement $gradinst $gradprog $bacontrols if `sample' == 1
*esttab using "$dir/DescriptiveStatsbyAward_`sample'.csv", label title(Descriptive Statistics) mtitle ("`sample'") cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") replace plain

* By Award Status 
eststo clear
bys award: eststo: estpost sum $pubs $pistats $placement $gradinst $gradprog $bacontrols if `sample' == 1
*esttab using "$dir/DescriptiveStatsbyAward_`sample'.csv", label title(Descriptive Statistics) cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") append plain
}

** Descriptive Statistics on CCA Sample for Coarsened & By Division
foreach sample in cca2cemsample {
eststo clear 
eststo: estpost sum $pubs $pistats $placement $gradinst $gradprog $bacontrols if `sample' == 1
*esttab using "$dir/DescriptiveStatsbyDiv_`sample'.csv", label title(Descriptive Statistics) mtitle ("`sample'") cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") replace plain

* By Divison Status 
eststo clear
bys div_cd: eststo: estpost sum $pubs $pistats $placement $gradinst $gradprog $bacontrols if `sample' == 1
*esttab using "$dir/DescriptiveStatsbyDiv_`sample'.csv", label title(Descriptive Statistics) cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") append plain
}

** Descriptive Statistics on CCA Sample for Coarsened & By Award Status & Division 
foreach sample in cca2cemsample {
eststo clear 
eststo: estpost sum $pubs $pistats $placement $gradinst $gradprog $bacontrols if `sample' == 1
*esttab using "$dir/DescriptiveStatsbyDivAwd_`sample'.csv", label title(Descriptive Statistics) mtitle ("`sample'") cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") replace plain

* By Divison & Award Status 
eststo clear
bys div_cd: eststo: estpost sum $pubs $pistats $placement $gradinst $gradprog $bacontrols if (`sample' == 1 & award == 1)
*esttab using "$dir/DescriptiveStatsbyDivAwd_`sample'.csv", label title(Awardee Descriptive Statistics) cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") append plain

eststo clear
bys div_cd: eststo: estpost sum $pubs $pistats $placement $gradinst $gradprog $bacontrols if (`sample' == 1 & award == 0)
*esttab using "$dir/DescriptiveStatsbyDivAwd_`sample'.csv", label title(HM Descriptive Statistics) cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") append plain
}

** Preliminary Diagnostics
* Test Statistical Difference of Pre-trend Variation by Award Status
	
* Prior Publications Variation  
ttest priorpubs if fullsample == 1, by(award)
bys div_cd: ttest priorpubs if fullsample == 1, by(award)

ttest total_article_cum5 if fullsample == 1, by(award)
bys div_cd: ttest total_article_cum5 if fullsample == 1, by(award)

* Program Variation 
ttest avg_citations_per_pub_nrc_dept if fullsample == 1, by(award)
bys div_cd: ttest avg_citations_per_pub_nrc_dept if fullsample == 1, by(award)

ttest avg_GRE_nrc_dept if fullsample == 1, by(award)
bys div_cd: ttest avg_GRE_nrc_dept if fullsample == 1, by(award)

ttest rank1 if fullsample == 1, by(award)
bys div_cd: ttest rank1 if fullsample == 1, by(award)

* Institution Variation 
ttest gradtype_cc2 if fullsample == 1, by(award)
bys div_cd: ttest gradtype_cc2 if fullsample == 1, by(award)

ttest gradpublic if fullsample == 1, by(award)
bys div_cd: ttest gradpublic if fullsample == 1, by(award)

foreach var in gradregion1 gradregion2 gradregion3 gradregion4 gradregion5 gradregion6 gradregion7 gradregion8 gradregion9 {
ttest `var' if fullsample == 1, by(award)
bys div_cd: ttest `var' if fullsample == 1, by(award)
}

* BA Institution Variation 
ttest bacpublic if fullsample == 1, by(award)
bys div_cd: ttest bacpublic if fullsample == 1, by(award)
	
ttest bac_cd1 if fullsample == 1, by(award)
bys div_cd: ttest bac_cd1 if fullsample == 1, by(award)

ttest bac_cd6 if fullsample == 1, by(award)
bys div_cd: ttest bac_cd6 if fullsample == 1, by(award)

********************************************************************************
				*** Up Next: Part 2 - Descriptive Figures ***
********************************************************************************
